/***********************************************
 This file is part of redia-bapps-main-ios.
 
 Copyright (c) 2015 Redia A/S
 
 Redia-bapps-main-ios is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 Redia-bapps-main-ios is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with redia-bapps-main-ios.  If not, see <http://www.gnu.org/licenses/>.
 
 *********************************************** */

//
//  BAPatron.m
//  redia-bapps-ios
//
//  Created by Nikolaj Tørring on 8/7/13.
//  Copyright (c) 2013 redia. All rights reserved.
//

#import "BAPatron.h"
#import "JSONEncodingHelperMethods.h"

@implementation BAPatron

+ (id)objectWithJSONObject:(NSDictionary *)jsonObj
{
    BAPatron *obj = [BAPatron new];
    
    
    obj.patronName = [JSONEncodingHelperMethods parseStringWithKey:@"patronName" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.patronName);
    
    obj.patronBranch = [JSONEncodingHelperMethods parseStringWithKey:@"patronBranch" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSString, obj.patronBranch);
    
    obj.roles = [JSONEncodingHelperMethods parseArrayOfStringsWithKey:@"roles" fromJsonObject:jsonObj];
    EXPECT_OBJECT(NSArray, obj.roles);
    
    return obj;
}

-(NSDictionary *)toJSONObject{
    EXPECT_OBJECT(NSString, self.patronName);
    EXPECT_OBJECT(NSString, self.patronBranch);

    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    if(self.patronName)[dict setObject:self.patronName forKey:@"patronName"];
    if(self.patronBranch)[dict setObject:self.patronBranch forKey:@"patronBranch"];
    
    return [NSDictionary dictionaryWithDictionary:dict];
}

@end
